/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.testis.nicmodule.core;

/**
 * bridge pattern implementation for lan interfaces
 * @author alperb
 */
public class Lan extends NetworkInterfaceController {

    public Lan(String s) {

        super.setInterfaceName(s);
        super.setNetworkOS();
    }

    /**
     * verification interface parameters method
     * passes parameters along with interface name to bridge's other side
     * @param all needed parameters in String
     * @return true/false to represent succes or fail
     */
    @Override
    public boolean verifyInterfaceConfiguration(String ip,
            String gateWay,
            String dns,
            String Subnet,
            String messageId) {
        return (this.getNetworkOs().verifyInterface(this.m_interfaceName,
                ip,
                gateWay,
                dns,
                Subnet, messageId));
    }

    /**
     * setandverify interface parameters method
     * first sets the interface and if the return value is true then verifies.
     * passes parameters along with interface name to bridge's other side
     * @param all needed parameters in String
     * @return true/false to represent succes or fail
     */
    @Override
    public boolean setAndVerifyInterfaceConfiguration(String ip,
            String gateWay,
            String dns,
            String Subnet,
            Boolean fromDhcp,
            String messageId) {
        boolean step1 = false,
                step2 = false;
        step1 = this.getNetworkOs().setInterfaceConfiguration(
                this.m_interfaceName,
                ip,
                gateWay,
                dns,
                Subnet,
                fromDhcp,
                messageId);
        if (step1) {
            step2 = this.getNetworkOs().verifyInterface(this.m_interfaceName,
                    ip,
                    gateWay,
                    dns,
                    Subnet, messageId);
            if (step2) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    /**
     * renewdhcpconfigiuration to renew lan interface parameters method
     * passes parameters along with interface name to bridge's other side
     * @return true/false to represent succes or fail
     */
    @Override
    public boolean renewDhcpConfiguration() {
        return (this.getNetworkOs().renewDHCPClient(this.m_interfaceName));
    }

    /**
     * adjust interface to enable/disable given interface
     * passes parameter along with interface name to bridge's other side
     * @param true for up / false for down
     * @return true/false to represent succes or fail
     */
    @Override
    public boolean adjustInterface(boolean toUp) {
        return (this.getNetworkOs().enableInterface(this.m_interfaceName,
                toUp));
    }
}
